#include "BaseType.h"
#include "Tracer.h"
using namespace std;
using namespace libemb;

/**
 * 设计模式：
 * 1.
 * 2.
 * 适用场景：
 * 1.
 * 2.
 **/

//审批人
class Approver{
DECL_CLASSNAME(Approver)
public:
    virtual void handleRequest()=0;
    void setNext(Approver* next){m_next=next;}
    Approver* getNext(){return m_next;}
protected:
    Approver* m_next{nullptr};
};

class TeamLeader:public Approver{
DECL_CLASSNAME(TeamLeader)
public:
    void handleRequest()
    {
        TRACE_INFO_CLASS("Team Leader handle you request...");
        if (getNext())
        {
            getNext()->handleRequest();
        }
        else
        {
            TRACE_INFO_CLASS("You request is approved.");
        }
    }
};

class TeamManager:public Approver{
DECL_CLASSNAME(TeamManager)
public:
    void handleRequest()
    {
        TRACE_INFO_CLASS("Team Manager handle you request...");
        if (getNext())
        {
            getNext()->handleRequest();
        }
        else
        {
            TRACE_INFO_CLASS("You request is approved.");
        }
    }
};

class CEO:public Approver{
DECL_CLASSNAME(CEO)
public:
    void handleRequest()
    {
        TRACE_INFO_CLASS("CEO handle you request...");
        if (getNext())
        {
            getNext()->handleRequest();
        }
        else
        {
            TRACE_INFO_CLASS("You request is approved.");
        }
    }
};

int main()
{
    Tracer::getInstance().setLevel(TRACE_LEVEL_DBG);
	Tracer::getInstance().addSink(std::make_shared<STDSink>()).start();

    TeamLeader leader;
    TeamManager manager;
    CEO ceo;
    //设置下一级审批者
    leader.setNext(&manager);
    manager.setNext(&ceo);
    
    //处理员工的请假申请
    leader.handleRequest();
    return RC_OK;
}